// routerStore

import {defineStore} from "pinia";
import {getStore} from "@/api/utils";

export const routerStore = defineStore('router', {
    state: () => {
        return {
            // 动态路由
            routers: [],
            // 异步路由标识
            asyncRoutesMark: false
        }
    },
    actions: {
        setAsyncRoutesMark(data) {
            this.asyncRoutesMark = data
        },
        setRouters(data) {
            this.routers = data
        }
    }
})

export const commonStore = defineStore('common', {
    state: () => {
        return {
            // 左侧菜单是否折叠
            isCollapse: false,
            // tags标签
            tagsNavList: getStore('tagsNavList') ? getStore('tagsNavList') : [{
                title: '主控台',
                name: 'home',
                path: '/dashboard'
            }],
            // 左侧菜单
            menuData: getStore('menus') ? getStore('menus') : [],
            // 附件类型id
            fileTypeDatum: []
        }
    },
    actions: {
        changeCollapse(data) {
            this.isCollapse = data;
        },
        addTagsNavList(data) {
            var res = this.tagsNavList.findIndex(item => item.path === data.path);
            res === -1 ? this.tagsNavList.push(data) : ''
        },
        changeMenuData() {
            console.log('开始修改')
            this.menuData = getStore('menus')
        },
        setFileTypeDatum(data) {
            this.fileTypeDatum = data
        }
    }
})
